package com.hq.fxh.No5_User.Jianli;

import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hq.fxh.Modle.CityModle;
import com.hq.fxh.R;

import java.util.List;



/**
 * /**
 *
 * @author 薛
 * @ClassName
 * @Description :
 * @Created 2017/9/25
 * @Email xlwenhao1858@sina.com
 */


public class LAdapterCity extends BaseAdapter {
    List<CityModle.DataBean> proData;
    List<CityModle.DataBean.CitysBean> cityData;
    int type=0;

    public void setType(int type) {
        this.type = type;
    }

    public void setProData(List<CityModle.DataBean> proData) {
        this.proData = proData;
    }

    public void setCityData(List<CityModle.DataBean.CitysBean> cityData) {
        this.cityData = cityData;
    }

    @Override
    public int getCount() {
        if (type == 0) {
            if (proData == null) {
                return 10;
            } else {
                return    proData.size();

            }
        } else if (type == 1) {
            return cityData == null ? 0 : cityData.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int i) {
        if (type == 1) {
            return cityData.get(i);
        } else if (type == 0) {
            return proData.get(i);
        }
        return null;
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup parent) {

        View view = convertView;
        ViewHolder viewHolder = null;
        if (view == null || !(view.getTag() instanceof ViewHolder)) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_spring_item, null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }

        switch (type) {
            case 0:
                if(proData!=null){
                    viewHolder.textListPlateName.setText(proData.get(i).getArea_name());

                }

                break;
            case 1:
                if(cityData!=null){
                    viewHolder.textListPlateName.setText(cityData.get(i).getArea_name());

                }

                break;
        }

        return view;
    }

    static class ViewHolder {
        protected TextView textListPlateName;
        protected LinearLayout layoutListPlateName;

        ViewHolder(View rootView) {
            initView(rootView);
        }

        private void initView(View rootView) {
            textListPlateName = (TextView) rootView.findViewById(R.id.text_List_PlateName);
            layoutListPlateName = (LinearLayout) rootView.findViewById(R.id.layout_List_PlateName);

        }
    }


}
